#pragma once

#include "my_disk_buf.h"
#include "comm/my_rwlock.h"
#include "comm/my_rbtree.h"

typedef struct my_disk_membufs_s my_disk_membufs_t;

struct my_disk_membufs_s {
    my_rwlock_t             rwlock;
    my_rbtree_t             rbtree;
    my_rbtree_node_t        sentinel;
};

static inline void
my_disk_membufs_init(my_disk_membufs_t *membufs) {
    my_rwlock_init(&membufs->rwlock);
    my_rbtree_init(&membufs->rbtree, &membufs->sentinel, my_rbtree_insert_value);
}

my_disk_buf_t * // object offset and object size
my_disk_membufs_get(my_disk_membufs_t *membufs, int64_t offset, int64_t size);

void
my_disk_membufs_put(my_disk_membufs_t *membufs, my_disk_buf_t *buf);

void
my_disk_membufs_del(my_disk_membufs_t *membufs, my_disk_buf_t *buf);